<template>
  <div class="card card-down">
    <div class="arrow-down" @click="Off"></div>
    <div class="head">
      <div class="head-switch-active-box">
        <div :class="[itemTemp.switch ? 'head-switch-active' : '']" class="head-switch" @click="Ok"></div>
      </div>
      <div class="head-title">{{ itemTemp.title }}</div>
    </div>
    <div class="body">
      <div class="content"></div>
      <div class="tail">
        <div class="time-box" @click="SetTime">
          <div class="time-img"></div>
          <div class="time-text">设置提醒时间</div>
        </div>
        <div class="del-text" @click="DelItem">删除</div>
      </div>
    </div>
  </div>
  <div class="mask1" @click="GoHome"></div>
</template>

<script setup>
import { defineProps, watch, defineEmits, reactive, ref } from 'vue';
const props = defineProps({
  switch: {
    type: Number,
    default: -1,
  },
  index: {
    type: Number,
    default: 0,
  },
  item: {
    type: Object,
    default: function () {
      return { switch: 0 };
    },
  },
});
// 监听 props.switch 的变化
watch(
  () => props.switch,
  (newValue) => {
    if (newValue) {
      itemTemp = props.item;
      No();
    }
  },
);

let itemTemp = reactive({});
const emit = defineEmits(['matter-content-return']);
function No() {
  console.log('打开事项详细卡片');
  document.querySelector('.card').classList.remove('card-down');
  document.querySelector('.mask1').style.display = 'block';
  document.querySelector('.card').style.zIndex = '99';
  document.querySelector('.mask1').style.zIndex = '98';
  Show();
}
function Off() {
  console.log('收起事项详细卡片');
  document.querySelector('.card').classList.add('card-down');
  document.querySelector('.mask1').style.display = 'none';
  emit('matter-content-return', {});
}
function GoHome() {
  emit('matter-content-return', {});
  Off();
}
function Show() {
  document.querySelector('.content').innerHTML = itemTemp.content;
}
function Ok() {
  document.querySelector('.head-switch').classList.add('head-switch-active');
  itemTemp.switch = 1;
  let data = {
    index: props.index,
    item: itemTemp,
    type: 1,
  };
  emit('matter-content-return', data);
  Off();
}
function SetTime() {
  console.log('设置时间');
}
function DelItem() {
  console.log('删除事项');
  let data = {
    index: props.index,
    item: itemTemp,
    type: 2,
  };
  emit('matter-content-return', data);
  Off();
}
</script>

<style scoped>
.card {
  border-radius: 16px 16px 0px 0px;
  position: absolute;
  width: 100%;
  height: 84.482758%;
  bottom: -1%;
  box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.1);
  transition: transform 1s ease;
  background-color: rgb(255, 255, 255);
  padding-left: 3.5%;
  padding-right: 3.5%;
}
.card-down {
  transform: translateY(100%);
}
.mask {
  position: absolute;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.4);
  display: none;
}
.arrow-down {
  position: absolute;
  top: 1%;
  margin: auto;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 20px solid transparent; /* 左边透明 */
  border-right: 20px solid transparent; /* 右边透明 */
  border-top: 5px solid rgb(202, 201, 201); /* 上边为黑色实心 */
  cursor: pointer;
}
.mask1 {
  position: absolute;
  top: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.4);
  display: none;
}
.head {
  width: 100%;
  margin-top: 4.51895%;
  height: 5%;
  display: flex;
  align-items: center;
}
.head-switch-active-box {
  height: 100%;
  aspect-ratio: 1;
  padding: 1.5%;
}
.head-switch {
  height: 100%;
  aspect-ratio: 1;
  border: 1px solid rgb(52, 120, 246); /* 边框为蓝色，2px粗细 */
  background-color: rgb(237, 244, 254); /* 背景色为灰色 */
  border-radius: 50%; /* 将元素设置为圆形 */
  cursor: pointer;
}
.head-switch-active {
  border: 1px solid blue;
  background-color: rgb(52, 120, 246);
}
.head-title {
  margin-left: 1%;
  display: flex;
  height: 100%;
  width: auto;
  text-align: center;
  font-size: 20px;
  font-weight: 500;
  letter-spacing: 0px;
  line-height: 28.96px;
  color: rgba(0, 0, 0, 0.85);
  vertical-align: top;
  align-items: center;
}
.body {
  margin-left: 10.5%;
  width: 87%;
  height: 92%;
}
.content {
  width: 100%;
  height: 90%;
  overflow-y: auto;
}
.tail {
  width: 100%;
  height: 10%;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.time-box {
  height: 100%;
  width: 70%;
  display: flex;
  align-items: center;
  cursor: pointer;
}
.time-img {
  height: 38%;
  aspect-ratio: 1;
  background: url(../../../public/time.svg);
  background-size: cover;
  background-repeat: no-repeat; /* 防止图片重复 */
  background-position: center; /* 图片居中显示 */
}
.time-text {
  margin-left: 2%;
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 0px;
  line-height: 21.72px;
  color: rgba(0, 0, 0, 0.85);
  text-align: left;
  vertical-align: top;
}
.del-text {
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 0px;
  line-height: 21.72px;
  color: rgba(255, 59, 48, 1);
  text-align: left;
  vertical-align: top;
  cursor: pointer;
}
@media (prefers-color-scheme: dark) {
  .card {
    background-color: rgba(27, 27, 29, 1);
    color: rgb(255, 255, 255);
  }
  .card * {
    background-color: rgba(27, 27, 29, 1);
    color: rgb(255, 255, 255);
  }
  .del-text {
    color: rgba(255, 59, 48, 1);
  }
  .head-switch-active {
    border: 1px solid blue;
    background-color: rgb(52, 120, 246);
  }
}
</style>
